package com.example.lets;

import android.content.Context;

/**
 * Created by Administrator on 2015/12/28.
 */
interface OnRefreshActListener {

    void onRefresh(PullToRefreshActLayout pullToRefreshActLayout);

    /**
     * 加载操作
     */
    void onLoadMore(PullToRefreshActLayout pullToRefreshActLayout);
}

class RefreshActListener implements OnRefreshActListener {

    private Context mContext;
    private PullToRefreshActLayout pullToRefreshActLayout;

    public RefreshActListener(Context mContext) {
        this.mContext = mContext;
    }

    @Override
    public void onRefresh(final PullToRefreshActLayout pullToRefreshActLayout) {
        this.pullToRefreshActLayout = pullToRefreshActLayout;
        if (mContext instanceof HomeActivity)
            ((HomeActivity) mContext).loadActivities(this, 1);
        else if (mContext instanceof UserActivityList)
            ((UserActivityList) mContext).loadActivities(this, 1);
    }

    @Override
    public void onLoadMore(PullToRefreshActLayout pullToRefreshActLayout) {
        this.pullToRefreshActLayout = pullToRefreshActLayout;
        if (mContext instanceof HomeActivity)
            ((HomeActivity) mContext).loadActivities(this, 0);
        else if (mContext instanceof UserActivityList)
            ((UserActivityList) mContext).loadActivities(this, 0);
    }

    public void loadFinish(int code, int num) {
        pullToRefreshActLayout.loadmoreFinish(code, num);
    }

    public void refreshFinish(int code) {
        pullToRefreshActLayout.refreshFinish(code);
    }
}